import { err, networkerr } from './base64';
const { mfutil } = getApp();
Page({
  async onLoad(query) {
    
    mfutil.onLoad(query);
    console.log(query);
    
    this.setData({
      code: query.code
    });
    my.hideLoading();
    my.hideShareMenu();
  },
  data: {
    code: 0,
    err: networkerr,
    openSetState: false
  },
  async onShow() {
    // 如果跳入过设置授权页面，进行判断之后回跳
    if (this.data.openSetState) {
      this.setData({ openSetState: false });
      // 判断用户权限 ，这里在刚授权成功时，获取到的值有问题
      // my.showToast({content: '权限检测中...'});
      my.showLoading({
        content: '权限检测中...',
        delay: 0,
        mask: true,
      });
      setTimeout(() => {
        my.getSetting({
          complete: res => {
            my.hideLoading();
            mfutil.logger.set({ origin: 'complete', msg: res });
            if (res && res.authSetting && res.authSetting.userInfo) {
              // 判断判断已经授权
              my.reLaunch({
                url: '/pages/index/index'
              });
              /* if (mfutil.config.oauthErrCallBackPage) {
                my.reLaunch({
                  url: mfutil.config.oauthErrCallBackPage
                });
              } else {
                my.showToast({ content: '授权成功,请重新进入' });
              } */
            } else {
              my.showToast({ content: '检测到暂未授权' });
            }
          }
        });
      }, 500);
    }
  },
  urlBack() {
    my.reLaunch({
      url: '/pages/index/index'
      // url:'pages/integral-page/integral-page'
    });
  },


  // 授权弹窗调起
  openSetting() {
    let that = this;
    my.getSystemInfo({
      success: (res) => {
        if (res.version != '10.3.0') {
          that.setData({ openSetState: true });
          my.openSetting({
            success: (res) => {
              res.authSetting = {
                "userInfo": true,
              }
            }
          })
        } else {
          my.reLaunch({
            url: '/pages/index/index'
          });
        }
      }
    })
  }
});
